Producer Consumer

The Producer-Consumer problem is a classical multi-process synchronization problem, that is we are trying to achieve synchronization between more than one process. There is one Producer in the producer-consumer problem, Producer is producing some items, whereas there is one Consumer that is consuming the items produced by the Producer. The same memory buffer is shared by both producers and consumers which is of fixed-size. The task of the Producer is to produce the item, put it into the memory buffer, and again start producing items. Whereas the task of the Consumer is to consume the item from the memory buffer..

Algorithm overview

This is the implementation of Producer Consumer algorithm. Here, we can have input of no. of process and along with that the time to see the visualization.

Input No. of process

Enter the no. of process you want to see being produced and consumed at any random instant of time.

Input total time

Here, enter the total amount of time, you want to carry out the visualization

Visualization

By clicking on Visualize, you will be able to see any random process being produced(will be shown with black colored box) and soon later being consumed(will be shown with white colored box).

Here, NOTE THAT out of all given processes, randomly any process will be picked and with that it will be consumed after a certain amount of time

Save PDF

By clicking on Save PDF, you will be able to download which process was produced and consumed at all instant of total time allotted to execute

Analysis of Producer Consumer approach

In computing, the producer-consumer problem (also known as the bounded-buffer problem) is a classic example of a multi-process synchronization problem. The problem describes two processes, the producer and the consumer, which share a common, fixed-size buffer used as a queue.
The producer’s job is to generate data, put it into the buffer, and start again.
At the same time, the consumer is consuming the data (i.e. removing it from the buffer), one piece at a time.

Problem:
To make sure that the producer won’t try to add data into the buffer if it’s full and that the consumer won’t try to remove data from an empty buffer.

Solution:
The producer is to either go to sleep or discard data if the buffer is full. The next time the consumer removes an item from the buffer, it notifies the producer, who starts to fill the buffer again. In the same way, the consumer can go to sleep if it finds the buffer to be empty. The next time the producer puts data into the buffer, it wakes up the sleeping consumer. An inadequate solution could result in a deadlock where both processes are waiting to be awakened.



abc